package zelix.gui.clickguis.kendall.components.impls;

import org.lwjgl.input.Mouse;
import zelix.gui.clickguis.kendall.components.Component;
import zelix.utils.hooks.visual.RenderUtils;
import zelix.utils.hooks.visual.font.FontLoaders;
import zelix.value.Mode;
import zelix.value.ModeValue;

public class KendallMode extends Component {
    public ModeValue value;
    public KendallButton parent;
    private int modeIndex;
    boolean previousmouse = true;
    boolean mouse;
    public KendallMode(ModeValue value, KendallButton parent){
        this.value = value;
        this.parent = parent;
    }

    @Override
    public void render(float x,float y,int mouseX, int mouseY){

        RenderUtils.drawBorderedRect(x,y,x+500/2,y+58/2,0,0,0xFF1F2022);
        FontLoaders.default14.drawString(this.value.getRenderName(),x+20/2f,y+5,0x99F5F5F7);
        RenderUtils.drawBorderedRect(x+20/2f,y+14,x+500/2-10,y+8+34/2,1,0xFF111111,0xFF181818);
        FontLoaders.default16.drawString(this.value.getSelectMode().getName(),x+20/2f+2,y+16,0xFFFFFFFF);

        if ( KendallButton.isButtonHovered(x+20/2f,y+14,x+500/2-10,y+8+32/2,mouseX,mouseY)){

            if (!this.previousmouse && Mouse.isButtonDown((int) 0)) {
                this.previousmouse = true;
                this.mouse = true;
            }

            if (this.mouse) {
                for (Mode sjh: this.value.getModes()) {
                    sjh.setToggled(false);
                }

                int maxIndex = this.value.getModes().length;
                modeIndex++;

                if (modeIndex + 1 > maxIndex)
                    modeIndex = 0;

                this.value.getModes()[modeIndex].setToggled(true);
                //////System.out.println("M.getValue() = " + M.getValue().getName());


                this.mouse = false;
            }

        }
        if (!Mouse.isButtonDown(0)) {
            this.previousmouse = false;
        }
    }


}